<?php
namespace app\controller;
use app\repository\UserRepository;
use app\NavComponent;
use app\HeadComponent;
use app\service\TemplateService;

class IndexController {
    public $extracts = [];

    public function __construct() {
        if (!UserRepository::isLogin()) {
            header('Location: login.view.php');
        }
    }

    public function index() {
        // 获取当前登录的用户姓名
        $user = UserRepository::getCurrentLoginUser();
        $this->extracts['user'] = $user;

        echo HeadComponent::render('首页');
        echo TemplateService::render('../view/index/index.html', $this->extracts);
    }
}